package main

import (
	"net"

	"gitee.com/yutiandou/wdRPC/common/connect"
	"gitee.com/yutiandou/wdRPC/loopup/handler"
	"gitee.com/yutiandou/wdtools/wdlog"
)

func main() {
	//lis, _ := net.Dial("tcp", ":1314")
	connpool := connect.NewConnPool(&handler.Connhand{})

	connpool.RegistHandler(1, handler.Purpose_NewNode_1)
	connpool.RegistHandler(2, handler.Purpose_NewClient_2)
	handler.Loopup_Timing(connpool)
	handler.ErgodicRoutTable()
	start(connpool)
}

func start(pool *connect.ConnPool) {
	lis, err := net.Listen("tcp", ":1314")
	if wdlog.PanicErr(err) {
		return
	}
	for {
		conn, err := lis.Accept()
		if wdlog.Error(err) {
			continue
		}
		pool.AddNewConn(conn)
	}

}
